package cz.muni.fi.pa165.musiclibrary.musiclibraryweb.components;

import org.apache.wicket.ajax.attributes.AjaxCallListener;
import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
import org.apache.wicket.ajax.markup.html.AjaxLink;

/**
 * A link that presents user with confirmation window with custom message.
 * 
 * @author Maros Kucbel
 * @date 2012-12-09T23:00:39+0100
 */
public abstract class ConfirmationLink<T> extends AjaxLink<T> {

    private final String text;

    public ConfirmationLink(String id, String text) {
        super(id);
        this.text = text;
    }

    @Override
    protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
        super.updateAjaxAttributes(attributes);

        AjaxCallListener ajaxCallListener = new AjaxCallListener();
        ajaxCallListener.onPrecondition("return confirm('" + this.text + "');");
        attributes.getAjaxCallListeners().add(ajaxCallListener);
    }
}